<template>
  <!--来料检验-->
  <div class="app-container">
    <el-form class="jc_search_wrap" v-model="searchList">
      <label>单晶编号</label><el-input v-model="searchList.crystalNo"></el-input>
      <label>单晶型号</label><el-input v-model="searchList.customerType"></el-input>
      <label>检验员</label><el-input v-model="searchList.inspecter"></el-input>
      <label>拼数</label>
      <el-select v-model="searchList.spelling">
        <el-option value="1">1</el-option>
        <el-option value="2">2</el-option>
        <el-option value="3">3</el-option>
        <el-option value="4">4</el-option>
        <el-option value="5">5</el-option>
        <el-option value="">未选择</el-option>
      </el-select>
      <br />
      <!-- <label>检验时间</label>
      <el-input type="date" v-model="searchList.date1"></el-input>至<el-input type="date" v-model="searchList.date2"></el-input> -->
        <label style="width:100px">检验开始时间:</label>
              <el-date-picker
                v-model="startDate"
                type="datetime"
                placeholder="选择日期时间">
              </el-date-picker>
              <label style="width:100px">检验结束时间:</label>
              <el-date-picker
                v-model="endDate"
                type="datetime"
                placeholder="选择日期时间">
              </el-date-picker>
      <el-button @click="searchRows"><i class="el-icon-search"></i>查询</el-button>
    </el-form>
    <el-button-group class="jc_btn_wrap jc_btn_left">
      <el-button @click="editRow"><i class="jc_icon"></i>编辑</el-button>
      <el-button @click="deleteRows"><i class="jc_icon"></i>删除</el-button>
      <el-button @click="exportRows"><i class="jc_icon"></i>导出</el-button>
      <el-button @click=""><i class=""></i>打印</el-button>
    </el-button-group>
    <el-table :data="list" :height="tableHeight-30" v-loading.body="listLoading" element-loading-text="拼命加载中" border fit highlight-current-row class="jc_table_wrap"  @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="80px" fixed>
      </el-table-column>
      <el-table-column label='单晶编号' width="230" fixed>
        <template scope="scope">
          {{scope.row.crystalNo}}
        </template>
      </el-table-column>
      <el-table-column label='规格' width="180">
        <template scope="scope">
          {{scope.row.norms}}
        </template>
      </el-table-column>
      <el-table-column label='单晶长度(mm)' width="120">
        <template scope="scope">
          {{scope.row.length}}
        </template>
      </el-table-column>
      <el-table-column label='有效长度(mm)' width="120">
        <template scope="scope">
          {{scope.row.effectLength}}
        </template>
      </el-table-column>
      <el-table-column label='崩损/灰皮/楞崩(总和)(mm)' width="190">
        <template scope="scope">
          {{scope.row.theSum}}
        </template>
      </el-table-column>
      <el-table-column label='亮斑/水印' width="100">
        <template scope="scope">
          {{scope.row.brightWater}}
        </template>
      </el-table-column>
      <el-table-column label='电阻率T' width="100">
        <template scope="scope">
          {{scope.row.resistivity}}
        </template>
      </el-table-column>
      <el-table-column label='电阻率W' width="100">
        <template scope="scope">
          {{scope.row.feild1}}
        </template>
      </el-table-column>
      <el-table-column label='端面斜T' width="100">
        <template scope="scope">
          {{scope.row.sideT}}
        </template>
      </el-table-column>
      <el-table-column label='端面斜W' width="100">
        <template scope="scope">
          {{scope.row.sideW}}
        </template>
      </el-table-column>
      <el-table-column label='检验员' width="100">
        <template scope="scope">
          {{scope.row.inspecter}}
        </template>
      </el-table-column>
      <el-table-column label='检验时间' width="210">
        <template scope="scope">
          {{scope.row.inspectTime}}
        </template>
      </el-table-column>
      <el-table-column label='晶体灰皮' width="100">
        <template scope="scope">
          {{scope.row.crystalGrey}}
        </template>
      </el-table-column>
      <el-table-column label='晶片灰皮' width="100">
        <template scope="scope">
          {{scope.row.chipGrey}}
        </template>
      </el-table-column>
      <el-table-column label='线痕' width="100">
        <template scope="scope">
          {{scope.row.lineMark}}
        </template>
      </el-table-column>
      <el-table-column label='厂牌' width="100">
        <template scope="scope">
          {{scope.row.factoryCard}}
        </template>
      </el-table-column>
      <el-table-column label='导电型号' width="100">
        <template scope="scope">
          {{scope.row.electricModel}}
        </template>
      </el-table-column>
      <el-table-column label='拼接' width="100">
        <template scope="scope">
          {{scope.row.seams}}
        </template>
      </el-table-column>
      <el-table-column label='检验结果' width="100">
        <template scope="scope">
          {{scope.row.judge}}
        </template>
      </el-table-column>
      <el-table-column label='备注'  width="210">
        <template scope="scope">
          {{scope.row.remark}}
        </template>
      </el-table-column>
    </el-table>
   <!-- <el-pagination layout="prev, pager, next" :total="total" @current-change="changePage" :page-size="10"/>-->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="changePage"
      :current-page="currentPage"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
    <!--编辑-->
    <el-dialog title="编辑" :visible.sync="edit_visible" class="jc_dialog_wrap">
      <el-form :model="form_edit" label-width="120px">
        <el-form-item label="晶段编号">
          <el-input v-model="form_edit.crystalNo"></el-input>
        </el-form-item>
        <el-form-item label="组合晶段编号">
          <el-input v-model="form_edit.crystalNoGroup"></el-input>
        </el-form-item>
        <el-form-item label="单晶长度">
          <el-input v-model="form_edit.length"></el-input>
        </el-form-item>
        <el-form-item label="有效长度">
          <el-input v-model="form_edit.effectLength"></el-input>
        </el-form-item>
        <el-form-item label="拼/整棒">
          <el-input v-model="form_edit.entire"></el-input>
        </el-form-item>
        <el-form-item label="崩损/灰皮/楞崩(总和)(mm)">
          <el-input v-model="form_edit.theSum"></el-input>
        </el-form-item>
        <el-form-item label="亮斑/水印">
          <el-input v-model="form_edit.brightWater"></el-input>
        </el-form-item>
        <el-form-item label="端面斜T">
          <el-input v-model="form_edit.sideT"></el-input>
        </el-form-item>
        <el-form-item label="端面斜W">
          <el-input v-model="form_edit.sideW"></el-input>
        </el-form-item>
        <el-form-item label="电阻率">
          <el-input v-model="form_edit.resistivity"></el-input>
        </el-form-item>
        <el-form-item label="判定">
          <el-input v-model="form_edit.judge"></el-input>
        </el-form-item>
        <el-form-item label="规格">
          <el-input v-model="form_edit.norms"></el-input>
        </el-form-item>
        <el-form-item label="检验员ID">
          <el-input v-model="form_edit.userID"></el-input>
        </el-form-item>
        <el-form-item label="检验员">
          <el-input v-model="form_edit.inspecter"></el-input>
        </el-form-item>
        <el-form-item label="检验时间">
          <el-input v-model="form_edit.inspectTime"></el-input>
        </el-form-item>
        <el-form-item label="拼缝">
          <el-input v-model="form_edit.seams"></el-input>
        </el-form-item>
        <el-form-item label="晶体灰皮（mm）">
          <el-input v-model="form_edit.crystalGrey"></el-input>
        </el-form-item>
        <el-form-item label="晶片灰皮（mm）">
          <el-input v-model="form_edit.chipGrey"></el-input>
        </el-form-item>
        <el-form-item label="线痕（mm）">
          <el-input v-model="form_edit.lineMark"></el-input>
        </el-form-item>
        <el-form-item label="厂牌">
          <el-input v-model="form_edit.factoryCard"></el-input>
        </el-form-item>
        <el-form-item label="崩损差">
          <el-input v-model="form_edit.lossValue"></el-input>
        </el-form-item>
        <el-form-item label="导电型号">
          <el-input v-model="form_edit.electricModel"></el-input>
        </el-form-item>
        <el-form-item label="单晶型号">
          <el-input v-model="form_edit.customerType"></el-input>
        </el-form-item>
        <el-form-item label="拼数">
          <el-input v-model="form_edit.spelling"></el-input>
        </el-form-item>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitEditForm">确定</el-button>
        <el-button @click="edit_visible=false">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

  import * as IQC from "../../api/report/incomeQualityControl";
  var moment = require('moment');
  export default {
    components: {

    },
    data() {
      return {
        searchList: {
          pageSize: '',
          customerType: '',crystalNo: '',inspecter: '',spelling: '',date1: '',date2: ''
        },
        list: null,
        total: 0,
        create_visible: false,
        detail_visible: false,
        edit_visible: false,
        form_create: {},
        form_detail: {},
        form_edit: {},
        multipleSelection: [],
        crystalNo: '',
        inspecter: '',
        customerType: '',
        spelling: '',
        startDate:'',
        endDate:'',
        pageSize: 10,
        currentPage: 1,
      }

    },
    created() {
      //this.fetchData()
    },
    methods: {
      fetchData(p=1) {
        this.listLoading = true;
        this.searchList.pageNum = this.currentPage = p;
        this.searchList.pageSize = this.pageSize;

        IQC.getList(this.searchList).then(data => {
          this.list = data.rows;
          this.total = parseInt(data.total);
          this.listLoading = false;
        })

      },
      searchRows() {
        // this.searchList.date1 = moment(this.startDate).format('YYYY-MM-DD HH:mm:ss');
        // this.searchList.date2 = moment(this.endDate).format('YYYY-MM-DD HH:mm:ss');
        if( !this.startDate == ''){
          this.searchList.date1 = moment(this.startDate).format('YYYY-MM-DD HH:mm:ss');
        }else{
          this.searchList.date1 = ''
        }
        if(!this.endDate == ''){
            this.searchList.date2 = moment(this.endDate).format('YYYY-MM-DD HH:mm:ss');
        }else{
          this.searchList.date2 = ''
        }
        this.fetchData()
      },
      editRow() {
        if(this.multipleSelection.length === 0) {
          alert('请先勾选行');
        }else if(this.multipleSelection.length >= 2) {
          alert('每次只能查看一行数据，请只勾选一行');
        }else if(this.multipleSelection.length === 1){
          this.edit_visible = true;
          IQC.detailRow(this.multipleSelection[0].id).then(data => {
            this.form_edit = data.msg;
          });
        }
      },
      submitEditForm() {
        IQC.updateRow(this.form_edit).then(data => {
          this.edit_visible = false;
          this.fetchData();
        })
      },
      deleteRows() {
        if(this.multipleSelection.length===0) {
          alert('请选择行');
        }else {
          var ids = [];
          for(var i in this.multipleSelection) {
            ids.push(this.multipleSelection[i].id)
          }
          this.$confirm('此操作将永久删除该行数据, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            IQC.delRows({ids: ids.join(',')}).then(data => {
              this.fetchData();
              this.$message({
                type: 'success',
                message: '删除成功!'
              });
            })

          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消删除'
            });
          });
        }
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      changePage(p) {
        this.fetchData(p)
      },
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
        this.pageSize = val;
        this.currentPage = 1;
        this.fetchData(1);

      },
      exportRows() {
        window.location.href=process.env.BASE_API+'/inspect/export?crystalNo='+this.searchList.crystalNo+'&customerType='+this.searchList.customerType+'&inspecter='+this.searchList.inspecter+'&spelling='+this.searchList.spelling+'&date1='+this.searchList.date1+'&date2='+this.searchList.date2;
      },
    },
    computed: {
      tableHeight() {
        const filterHeight = 28
        var tableHeight = this.getTableHeight(filterHeight)
        return tableHeight;
      }
    },
    mounted () {
      this.startDate = moment.utc(moment().subtract(1, 'days').format('YYYY-MM-DD 00:30:00')).format();
      this.endDate = moment.utc(moment().format('YYYY-MM-DD 00:30:00')).format();
      this.searchRows();
    }
  }
</script>
